import time
import json

with open('leader.json', 'r') as file:
    data = json.load(file)
list_data = data['data']['list']

previous_statuses = None

while True:
    with open('leader.json', 'r') as file:
        data = json.load(file)
    # {"id": {"symbol": "", "opened": "", "avgCost": "", "status":""}}
    # current_statuses = {item['id']: item['status'] for item in data['data']['list']}
    current_statuses = {item['id']: {key: value for key, value in item.items()} for item in data['data']['list']}

    if previous_statuses is not None:
        # 检查list的新增项
        new_items = set(current_statuses.keys()) - set(previous_statuses.keys())
        if new_items:
            for new_id in new_items:
                previous_statuses[new_id] = current_statuses[new_id]
                print(f"New items added with id: {new_id}")

        # 检查status的变化
        for item_id, item in current_statuses.items():
            status = item['status']
            if previous_statuses.get(item_id)['status'] != status:
                print(f"Item with id {item_id} has changed status from {previous_statuses[item_id]} to {status}")


    previous_statuses = current_statuses

    # 等待一段时间后再检查
    time.sleep(5)  # 例如，每10秒检查一次
